package edu.stu.cs.software.family.customer.web.spring.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import edu.stu.cs.software.family.base.web.spring.controller.GenericController;
import edu.stu.cs.software.family.customer.domain.Customer;
import edu.stu.cs.software.family.customer.service.CustomerManager;

@Controller
@RequestMapping("/customer")
public class CustomerController extends GenericController<Customer, Long, CustomerManager> {

	CustomerManager customerManager;
	
	@PostMapping("/login")
	public String dologin(@RequestParam String userName,@RequestParam String password)
	{
		
		Customer customer = this.customerManager.findByCustomerName(userName);
		if (customer == null) {
            return "error";
        }
        if (!password.equals(((Customer) customer).getPassword())) {
            return "error";
        }
        return "success";
	}
	
	@Autowired
	public void setCustomerManager(CustomerManager customerManager) {
		this.customerManager = customerManager;
		this.manager = this.customerManager;
	}
}
